﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace P2PWeb.Common
{
    public static class EnumHelper
    {
        public static string GetDisplayName(this Enum state)
        {
            var displayNameAttribute = state.GetType().GetMember(state + "")[0].GetCustomAttributes(false).First(f => f is EnumDisplayName);
            return (displayNameAttribute as EnumDisplayName).DisplayName;
        }

        public static SelectList ConverToSelectList(Type enumType, int enumValue, bool isAddPleaseSelect = false)
        {
            List<Tuple<string, int>> items = new List<Tuple<string, int>>();
            if (isAddPleaseSelect)
            {
                items.Add(new Tuple<string, int>("请选择", -1));
            }
            foreach (var value in (Enum.GetValues(enumType)))
            {
                int intValue = (int)value;
                string stringText = GetDisplayName((Enum)value);
                items.Add(new Tuple<string, int>(stringText, intValue));
            }
            return new SelectList(items, "Item2", "Item1", enumValue);
        }
    }

    public class EnumDisplayName : Attribute
    {
        public EnumDisplayName(string displayName)
        {
            this.DisplayName = displayName;
        }
        public string DisplayName { get; set; }
    }


    public enum CampaignState
    {
        [EnumDisplayName("草稿")]
        /// <summary>
        /// 草稿
        /// </summary>
        Draft = 1,


        [EnumDisplayName("审核阶段")]
        /// <summary>
        /// 审核中..
        /// </summary>
        LookThrough = 2,

        [EnumDisplayName("投标中")]
        /// <summary>
        /// 投标中
        /// </summary>
        Financing = 3,

        [EnumDisplayName("已满标")]
        /// <summary>
        /// 已满标
        /// </summary>
        /// 
        Finish = 4,

        [EnumDisplayName("审核失败")]
        /// <summary>
        /// 审核失败
        /// </summary>
        Cancel = 5,

        [EnumDisplayName("投标失败")]
        /// <summary>
        /// 投标失败
        /// </summary>
        FinancialFailure = 6
    }

    public enum CalcType
    {
        [EnumDisplayName("等额本息")]
        /// <summary>
        /// 等额本息
        /// </summary>
        LookThrough = 1,

        [EnumDisplayName("等额本金")]
        /// <summary>
        /// 等额本金
        /// </summary>
        Financing = 2,

        [EnumDisplayName("每月还息，到期还本")]
        /// <summary>
        /// 每月还息，到期还本
        /// </summary>
        WaitForTheRepayment = 3,
        [EnumDisplayName("购买成功立刻起息")]
        /// <summary>
        /// 每月还息，到期还本
        /// </summary>
        BuyNow = 4,
    }

    public enum BorrowUse
    {
        [EnumDisplayName("请选择")]
        none = -1,

        [EnumDisplayName("购房")]
        /// <summary>
        /// 购房
        /// </summary>
        BuyHouse = 1,

        [EnumDisplayName("购车")]
        /// <summary>
        /// 购车
        /// </summary>
        BuyCar = 2,

        [EnumDisplayName("结婚")]
        /// <summary>
        /// 结婚
        /// </summary>
        Marry = 3,

        [EnumDisplayName("创业")]
        /// <summary>
        /// 创业
        /// </summary>
        Business = 4,

        [EnumDisplayName("教育培训")]
        /// <summary>
        /// 教育培训
        /// </summary>
        EducationalTraining = 5,

        [EnumDisplayName("家具")]
        /// <summary>
        /// 家具
        /// </summary>
        PurchaseOfFurniture = 6,

        [EnumDisplayName("装修")]
        /// <summary>
        /// 装修
        /// </summary>
        Fitment = 7,

        [EnumDisplayName("旅游")]
        /// <summary>
        /// 旅游
        /// </summary>
        Trip = 8,

        [EnumDisplayName("医疗")]
        /// <summary>
        /// 医疗
        /// </summary>
        Medical = 9,

        [EnumDisplayName("日常消费")]
        /// <summary>
        /// 日常消费
        /// </summary>
        Spend = 10,

        [EnumDisplayName("偿还债务")]
        /// <summary>
        /// 偿还债务
        /// </summary>
        PaymentOfDebts = 11,

        [EnumDisplayName("投资")]
        /// <summary>
        /// 投资
        /// </summary>
        Invest = 12,

        [EnumDisplayName("其它")]
        Other = 13,
    }

    public enum MortgageAttachment
    {
        [EnumDisplayName("银票宝")]
        House = 1,

        [EnumDisplayName("商票宝")]
        Car = 2,
        [EnumDisplayName("银行理财类")]
        Credit = 3,
    }

    public enum AccountAuthenticationState
    {
        [EnumDisplayName("已上传资料")]
        Finish = 2,

        [EnumDisplayName("还没有上传资料")]
        unfinished = 1,
    }

    public enum AccountState
    {
        [EnumDisplayName("新注册用户")]
        New,

        [EnumDisplayName("正在审核中")]
        LookThrough,

        [EnumDisplayName("审核通过")]
        Pass,

        [EnumDisplayName("审核失败")]
        Unfit
    }

    public enum CampUpLoadState
    {
        [EnumDisplayName("材料上传完毕")]
        Finish = 2,

        [EnumDisplayName("材料未上传完成")]
        unfinished = 1,

        [EnumDisplayName("材料审核失败")]
        Cancel,
    }

    public enum AccountType
    {
        [EnumDisplayName("普通用户")]
        User = 1,

        [EnumDisplayName("系统管理员")]
        Admin = 2,

        [EnumDisplayName("审核人员")]
        LookThrough = 3,

        [EnumDisplayName("代理商")]
        Agent = 4,
    }

    public enum CampanyType
    {
        [EnumDisplayName("机关及事业单位")]
        AuthoritiesAndPublicInstitutions = 1,

        [EnumDisplayName("国营")]
        StateOwnedEnterprise = 2,

        [EnumDisplayName("民营")]
        PrivateEnterprise = 3,

        [EnumDisplayName("三资企业")]
        WithThreeKindsOfCapital = 4,
    }

    public enum EducationType
    {
        [EnumDisplayName("初中")]
        ChuZhong = 1,
        [EnumDisplayName("高中")]
        GaoZhong = 2,
        [EnumDisplayName("大专")]
        DaZhuan = 3,
        [EnumDisplayName("本科")]
        BenKe = 4,
        [EnumDisplayName("硕士")]
        ShuoShi = 5,
        [EnumDisplayName("博士")]
        BoShi = 6,
        [EnumDisplayName("博士后")]
        BoShiHou = 7,
    }


    public enum MaritalType
    {
        [EnumDisplayName("未婚")]
        Unmarried = 1,
        [EnumDisplayName("离异")]
        Divorced = 2,
        [EnumDisplayName("丧偶")]
        BereftOfOneSpouse = 3,
        [EnumDisplayName("已婚有子")]
        MarriedWithChildren = 4,
        [EnumDisplayName("已婚无子")]
        MarriedWithoutChildren = 5
    }

    public enum HouseInfoType
    {
        [EnumDisplayName("有房有房贷")]
        HaveHouseAndHaveMortgage = 1,
        [EnumDisplayName("有房无房贷")]
        HaveHouseUnMortgage = 2,
        [EnumDisplayName("无房")]
        NotHaveHouse = 3,
    }

    public enum FamilyMemberType
    {
        [EnumDisplayName("父母")]
        Parent = 1,
        [EnumDisplayName("配偶")]
        Spouse = 2,
        [EnumDisplayName("子女")]
        Children = 3,
        [EnumDisplayName("其它")]
        Other = 4,
    }

    public enum WorkContact
    {
        [EnumDisplayName("同事")]
        Colleague = 1,
        [EnumDisplayName("人事")]
        Hr = 2,
        [EnumDisplayName("其它")]
        Other = 3,
    }

    public enum OtherContact
    {
        [EnumDisplayName("同学")]
        Classmate = 1,

        [EnumDisplayName("朋友")]
        Friend = 2,

        [EnumDisplayName("老师")]
        Teacher = 3,
        [EnumDisplayName("其它")]
        Other = 4,
    }

    public enum SexType
    {

        [EnumDisplayName("男")]
        Man = 1,

        [EnumDisplayName("女")]
        Women = 2
    }

    public enum AgentType
    {
        [EnumDisplayName("普通代理商")]
        common=1
    }

    public enum CampUpLoadType
    {
        [EnumDisplayName("个人")]
        Person=1,
        [EnumDisplayName("代理商")]
        Agent=2
    }
}